﻿using AIPlugin.Fetures;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AIPlugin.Core
{
    public class AIClient
    {
        private readonly IServiceProvider _serviceProvider;

        /// <summary>
        /// 动态通知功能模块入口
        /// </summary>
        public CodeAssistantService CodeAssistant => GetService<CodeAssistantService>();


        public AIClient(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }

        private T GetService<T>() where T : class
        {
            return _serviceProvider.GetService<T>()
             ?? throw new ModuleNotLoadedException(
                    $"{typeof(T).Name} 模块未加载，请在初始化时调用 features.Add{typeof(T).Name.Replace("Service", "")}()");

        }
        /// <summary>
        /// 模块未加载专用异常
        /// </summary>
        public class ModuleNotLoadedException(string message) : Exception(message)
        {
        }

    }
}
